package com.igeekhome.ccs.controller;

import com.igeekhome.ccs.biz.IDataView;
import com.igeekhome.ccs.entity.Session;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("dataView")
public class DataViewController {
    @Autowired
    IDataView iDataView;



    @RequestMapping("allsession")
    public @ResponseBody
    int allsession(int groupId,int customerId,String startTime,String endTime){
        return iDataView.allsession(groupId,customerId,startTime,endTime);
    }
    @RequestMapping("allcustomer")

    public @ResponseBody
    int allcustomer(int groupId,int customerId,String startTime,String endTime){
        return iDataView.allcustomer(groupId,customerId,startTime,endTime);
    }
    @RequestMapping("allaccess")
    public @ResponseBody
    int allaccess(int groupId,int customerId,String startTime,String endTime){
        return iDataView.allaccess(groupId,customerId,startTime,endTime);
    }
    /**
     * 总消息数
     */
    @RequestMapping("allmessage")
    public @ResponseBody
    int allmessage(int groupId,int customerId,String startTime,String endTime){
        return iDataView.allmessage(groupId,customerId,startTime,endTime);
    }
    /**
     * 平均会话时长
     */
    @RequestMapping("avgSessionTime")
    public @ResponseBody
    int avgSessionTime(int groupId,int customerId,String startTime,String endTime){
        List<Session> sessions=iDataView.getallsession(groupId,customerId,startTime,endTime);
        int sumtime=0;
        int least=0;
        for(int i=0;i<sessions.size();i++){
            if(sessions.get(i).getEndTime()==null||sessions.get(i).getBeginTime()==null){
                least++;
            }
            else{
                long time2 = sessions.get(0).getBeginTime().getTime();
                long time3 =sessions.get(0).getEndTime().getTime();
                long time4=(time3-time2)/1000;
                sumtime+=time4;
            }
        }

        System.out.println(sumtime/(sessions.size()-least));
        return 0;
    }
    /**
     * 好评率
     * 这个看大家要不要求搞这个
     */
    /**
     * 一次性解决问题率
     * 看大家意见搞不搞
     */
    /**
     * 总人工会话数
     * 看大家意见搞不搞
     */
}
